<script type="text/javascript">
  $(document).ready(function(){
      $('#checkKri').click(function(){
          if($('.check').val() == 1){
              $('.kri').attr('checked', 'checked');
              $('.bobot').removeAttr('disabled');
              $('.check').val('0');
              $('.krit').val('0');
          }else{
              $('.kri').removeAttr('checked');
              $('.bobot').attr('disabled', 'disabled');
              $('.check').val('1');
              $('.krit').val('1');
          }
      })
  })
  function checksKri(num){
      if($('#bobot'+num).is(':disabled')){
          $('#bobot'+num).removeAttr('disabled');
          $('#nilai_bobot'+num).removeAttr('disabled');
          $('#krit'+num).val('0');
      }else{
          $('#bobot'+num).attr('disabled', 'disabled');
          $('#nilai_bobot'+num).attr('disabled', 'disabled');
          $('#krit'+num).val('1');
      }
  }
  function ubahBobot(num){
      var value = $('#bobot'+num).val();
      $('#nilai_bobot'+num).val(value);
  }
</script>
<div class="data-list">
    <fieldset>
        <legend><?php echo "$formTitle";?></legend>
        <?php
          echo form_open($subLink);
        ?>    
        <table class="tabel" style="width: 50%">
            <tr>
                <th>
                    <?php
                      echo form_checkbox('', '', FALSE, 'id=checkKri');
                      echo '<input type=hidden value=1 class=check>';
                    ?>
                </th>
                <th>Nama</th>
                <th>Jenis</th>
                <th>Bobot</th>
            </tr>
            <?php
            $no = 1;
            $sess_kri = $this->session->userdata('kriteria');
            foreach ($kriteria as $kri){
            ?>
            <tr class="<?php echo ($no%2)?'even':'odd';?>">
                <td style="width: 5%;">
                    <?php
                      $cek = in_array($kri['id'], $sess_kri['id']);
                      if($cek){
                          $checked = TRUE;
                          $disabled = '';
                      }else{
                          $checked = FALSE;
                          $disabled = 'disabled';
                      }
                      
                      echo form_checkbox('id[]', $kri['id'], $checked, 'class=kri id=kri'.$no.' onclick=checksKri('.$no.')');
                      echo form_hidden('jenis[]', $kri['jenis']);
                      echo form_hidden('nama[]', $kri['nama']);
                      echo '<input type=hidden value=1 class=krit id=krit'.$no.'>';
                    ?>
                </td>
                <td><?php echo $kri['nama'];?></td>
                <td style="width: 10%;"><?php echo $kri['jenis'];?></td>
                <td style="width: 20%;">
                    <select name="bobot[]" id="bobot<?php echo "$no";?>" class="bobot" onchange="ubahBobot(<?php echo "$no";?>)" <?php echo "$disabled";?>>
                        <?php 
                        foreach ($tingkatKepentinganKriteria as $tk){
                        ?>
                        <option value="<?php echo $tk['id'];?>"><?php echo $tk['nilai'];?></option>
                        <?php
                        }
                        ?>
                    </select>   
                    <input type="hidden" name="nilai_bobot[]" id="nilai_bobot<?php echo "$no";?>" value="<?php echo $tingkatKepentinganKriteria[0]['id'];?>" <?php echo "$disabled";?>/>
                </td>
            </tr>
            <?php
            $no++;
            }
            ?>
        </table>
        <?php
          echo form_button('back', 'Kembali', 'class=prev onClick='."javascript:location.href='".base_url()."index.php/pemilihan_adik_asuh/'".'');
          echo form_submit("add", "Selanjutnya", "class='next' style='margin-right:2px'");
          echo form_close();
        ?>
    </fieldset>    
</div>